<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>寻找另一句</title>
    <script src="https://cdn.staticfile.org/qrcodejs/1.0.0/qrcode.min.js"></script>
    <style>
        body {
            font-family: 'Segoe UI', '圆体', Yuanti, sans-serif;
            background: #f0f9eb;
            color: #3a6351;
            min-height: 100vh;
            padding: 20px;
            margin: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .container {
            background: rgba(255, 255, 255, 0.9);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            width: 90%;
            text-align: center;
            position: relative;
        }

        h1 {
            color: #4a7867;
            margin-bottom: 30px;
            font-weight: 300;
            letter-spacing: 2px;
        }

        #qrcode {
            margin: 20px auto;
            padding: 10px;
            background: white;
            border-radius: 8px;
        }

        button {
            background: linear-gradient(135deg, #8dcca9 0%, #5ca07c 100%);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            font-size: 18px;
            cursor: pointer;
            transition: transform 0.2s;
            margin: 20px 0;
        }

        #result {
            font-size: 24px;
            min-height: 60px;
            margin: 20px 0;
            padding: 15px;
            background: #f5fff9;
            border-radius: 10px;
            animation: fadeIn 0.5s;
        }

        #drawn-list {
            text-align: left;
            margin: 20px auto;
            max-width: 300px;
        }

        .edit-panel {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.2);
            z-index: 100;
        }

        #editText {
            width: 300px;
            height: 200px;
            margin: 10px 0;
            padding: 10px;
            border: 1px solid #8dcca9;
            border-radius: 8px;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🌸 寻找另一句 🌸</h1>
        <div id="qrcode"></div>
        <button onclick="drawLot()">开始寻找</button>
        <div id="result"></div>
        <div id="drawn-list"></div>
        <button style="position:absolute;top:15px;right:15px;padding:8px 15px;font-size:14px;" 
                onclick="showEditor()">编辑签文</button>
    </div>

    <div class="edit-panel" id="editPanel" style="display:none;">
        <h3>编辑签文（每行一句）</h3>
        <textarea id="editText"></textarea>
        <div>
            <button onclick="saveLots()">保存</button>
            <button onclick="closeEditor()">取消</button>
        </div>
    </div>

    <script>
        // 初始化签文
        let lots = loadLots();
        let remainingLots = [...lots];
        let qrcodeGenerated = false;

        function loadLots() {
            const saved = localStorage.getItem('customLots');
            return saved ? saved.split('\n') : [
                "云卷云舒自有期", 
                "明月何曾是两乡",
                "春风化雨润无声",
                "星河长明照归途",
                "一叶知秋意渐浓",
                "静水流深自有声",
                "青山不语仍自在",
                "花开有时待重逢",
                "林深见鹿遇初心",
                "闲云潭影日悠悠",
                "雪落无痕心有印",
                "沧海月明珠有泪"
            ];
        }

        function drawLot() {
            if (remainingLots.length === 0) {
                document.getElementById('result').innerHTML = "🎉 所有缘分已找到归属";
                return;
            }

            const randomIndex = Math.floor(Math.random() * remainingLots.length);
            const drawnLot = remainingLots.splice(randomIndex, 1)[0];
            
            document.getElementById('result').innerHTML = `🍃 你的专属签文：<br><strong>${drawnLot}</strong>`;
            
            const listItem = document.createElement('div');
            listItem.textContent = `• ${drawnLot}`;
            document.getElementById('drawn-list').appendChild(listItem);

            if (!qrcodeGenerated) {
                generateQRCode();
                qrcodeGenerated = true;
            }
        }

        function generateQRCode() {
            const url = window.location.href.startsWith('http') ? 
                window.location.href : 
                'https://您的域名.com/抽签页面.html';
            
            new QRCode(document.getElementById("qrcode"), {
                text: url,
                width: 128,
                height: 128,
                colorDark : "#4a7867",
                colorLight : "#ffffff",
                correctLevel : QRCode.CorrectLevel.H
            });
        }

        function showEditor() {
            document.getElementById('editPanel').style.display = 'block';
            document.getElementById('editText').value = loadLots().join('\n');
        }

        function closeEditor() {
            document.getElementById('editPanel').style.display = 'none';
        }

        function saveLots() {
            const newLots = document.getElementById('editText').value
                .split('\n')
                .map(line => line.trim())
                .filter(line => line);

            if (newLots.length !== 12) {
                alert('请确保输入正好12句签文');
                return;
            }

            localStorage.setItem('customLots', newLots.join('\n'));
            lots = newLots;
            remainingLots = [...lots];
            document.getElementById('drawn-list').innerHTML = '';
            document.getElementById('result').innerHTML = '';
            closeEditor();
        }
    </script>
</body>
</html>